<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 无条件成功
        /*       Promise.resolve('必须成功').then(res => {
                  console.log(res)
              })
      
              Promise.resolve('success').then(res => console.log(res))
              Promise.resolve('success').then(res => console.log(res)) */


        //无条件失败
        /*   Promise.reject('必须失败').catch(err => {
              console.log(err)
          })
          Promise.reject('fail').catch(err => console.log(err))
          Promise.reject('fail').catch(err => console.log(err)) */


        let successFn = (data) => Promise.resolve(data)
        let arr = [];
        for (let i = 0; i < 3; i++) {
            arr.push(successFn('成功' + i))
        }
        // arr.push(Promise.reject('fail'))

        //all  所有的都成功才成功   只要有一个失败了就失败
        Promise.all(arr)
            .then(arrData => console.log(arrData))
            .catch(err => console.log(err))

        Promise.all(arr).then(res => console.log(res)).catch(err => console.log(err))
        Promise.all(arr).then(res => console.log(res)).catch(err => console.log(err))

        let arr2 = [Promise.reject('fail1'), Promise.resolve('success1'), Promise.resolve('success2')]
        Promise.race(arr2)
            .then((res) => console.log(res))
            .catch(err => console.log(err))
        Promise.race(arr2).then(res => console.log(res)).catch(err => console.log(err))
        Promise.race(arr2).then(res => console.log(res)).catch(err => console.log(err))
    </script>
</body>

</html>